package com.edu.exam.entity.examination.paper;

import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;

/**
 * 冲突检测实体类
 * 冲突检测结果记录，存储检测到的冲突信息和解决方案
 *
 * @author S-01 Module Designer
 * @version 2.0
 * @since 2025-11-10
 */
@Entity
@Data
@EqualsAndHashCode(callSuper = false)
public class ConflictDetection {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "plan_id", nullable = false)
    private Long planId;

    @Column(name = "conflict_type", length = 50, nullable = false)
    private String conflictType;

    @Column(name = "conflict_level", length = 50, nullable = false)
    private String conflictLevel;

    @Column(name = "conflict_description", columnDefinition = "TEXT")
    private String conflictDescription;

    @Column(name = "conflicting_resource_id", length = 50)
    private String conflictingResourceId;

    @Column(name = "conflicting_resource_name", length = 200)
    private String conflictingResourceName;

    @Column(name = "conflicting_item_id_1")
    private Long conflictingItemId1;

    @Column(name = "conflicting_item_id_2")
    private Long conflictingItemId2;

    @Column(name = "conflicting_time_1")
    private LocalDateTime conflictingTime1;

    @Column(name = "conflicting_time_2")
    private LocalDateTime conflictingTime2;

    @Column(name = "resolution", columnDefinition = "TEXT")
    private String resolution;

    @Column(name = "resolution_strategy", length = 100)
    private String resolutionStrategy;

    @Column(name = "auto_resolved", nullable = false)
    private Boolean autoResolved = false;

    @Column(name = "detection_status", length = 50, nullable = false)
    private String detectionStatus;

    @Column(name = "detection_time")
    private LocalDateTime detectionTime;

    @Column(name = "resolved_by", length = 64)
    private String resolvedBy;

    @Column(name = "resolved_time")
    private LocalDateTime resolvedTime;

    @Column(name = "impact_assessment", columnDefinition = "TEXT")
    private String impactAssessment; // 影响评估

    @Column(name = "alternative_suggestions", columnDefinition = "TEXT")
    private String alternativeSuggestions; // 替代方案建议

    @CreationTimestamp
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    @UpdateTimestamp
    @Column(name = "updated_time")
    private LocalDateTime updatedTime;

    @Version
    @Column(name = "version", nullable = false)
    private Integer version = 1;

    // 关联实体
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "plan_id", insertable = false, updatable = false)
    private SpecialExamPlan plan;
}